<?php
$this->breadcrumbs = array(
    JobType::$names[$type],
);
?>

<?php /** @var BootActiveForm $form */
    $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id'=>'job',
    'type'=>'search',
    'enableClientValidation'=>true,
    'clientOptions'=>array(
        'validateOnSubmit'=>true,
    ),
)); ?>
<div class="box">
<?php echo $form->dropDownListRow($model, 'submit_time', TimeSpan::$names, array('class'=>'input-medium')); ?>
&nbsp;&nbsp;
<?php echo $form->dropDownListRow($model, 'job_frequency', Frequency::$names, array('class'=>'input-small')); ?>
&nbsp;&nbsp;
<?php echo $form->textFieldRow($model, 'job_name', array('class'=>'input-large', 'prepend'=>'<i class="icon-search"></i>')); ?>
&nbsp;&nbsp;
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'label'=>'搜索')); ?>
</div>

<script>
function reloadGrid(data) {
    $.fn.yiiGridView.update('job-grid');
}
function checkSelect() {                                                  
    if($.fn.yiiGridView.getSelection("job-grid") == "") {
        alert('请选择至少一条记录');                                                    
        return false;                                                  
    }
    else {
        return true;
    }
}
</script>

<div class="btn-toolbar">

<?php $this->widget('bootstrap.widgets.TbButton', array(
    'type'=>'danger',
    'buttonType'=>'ajaxSubmit',
    'size'=>'small',
    'icon'=>'remove white',
    'label'=>'标记删除', 
    'url'=>array('job/ajaxDelete'), 
    'ajaxOptions'=>array(
        'beforeSend'=>  'checkSelect',
        'success'   =>  'reloadGrid',
    ),
    'htmlOptions'=>array(
        'confirm'=>'确认要删除吗?',
    ),

)); ?>

<?php $this->widget('bootstrap.widgets.TbButton', array(
    'type'=>'primary',
    'label'=>'新建作业',
    'icon'=>'plus white',
    'url'=>array('job/create', 'type' => $_GET['type']),
    'size'=>'small',
     
)); ?>

<?php $this->widget('bootstrap.widgets.TbButton', array(
    'type'=>'primary',
    'label'=>'手动执行',
    'icon'=>'hand-right white',
    'size'=>'small',
    'htmlOptions'=>array(
        'data-toggle'=>'modal',
        'data-target'=>'#myModal',
    ),
)); ?>

</div>
<?php $this->widget('bootstrap.widgets.TbGridView', array(
    'id' => 'job-grid',
    'type'=>'striped bordered condensed',
    'dataProvider'  =>  $dataProvider,
    'pager'=>array(
        'class'=>'CLinkPager',           
        'nextPageLabel'=>'下一页>',           
        'prevPageLabel'=>'<上一页',           
        'header'=>'',   
    ),   
    'selectableRows'=> 2,
    'summaryText'   =>  '显示{start}-{end}条.共{count}条记录,当前第{page}页',
    'template'      =>  '{items}{pager}',
    'columns'       =>  array(
       array(
            'id'    =>  'autoId',
            'class' =>  'CCheckBoxColumn',
        ),
        array(
            'header'=>  '#',
            'name'  =>  'job_id',
            'value' =>  '$data->job_id'
        ),
       array(
            'name'  =>  'job_name',
            'type'  =>  'raw',
            'value' =>  'CHtml::link(CHtml::encode($data->job_name), Yii::app()->controller->createUrl("job/update", array("job_id"=>$data->job_id)))',
        ),
        array(
            'name'  =>  'user_id',
            'value' =>  '$data->user->user_name'
        ),
        array(
            'name'  =>  'job_type',
            'value' =>  'JobType::$names[$data->job_type]'
        ),
        array(
            'header'=>  '周期',
            'name'  =>  'job_frequency',
            'value' =>  'Frequency::$names[$data->job_frequency]'
        ),
        array(
            'header'=>  '优先级',
            'name'  =>  'job_priority',
            'value' =>  'Priority::$labels[$data->job_priority]'
        ),
        array(
            'name'  =>  'submit_time',
            'value' =>  '$data->submit_time'
        ), 
        array(
            'header'=>  '工作流',
            'type'  =>  'raw',
            'name'  =>  'workflow_name',
            'value' =>  'CHtml::link(CHtml::encode($data->workflow_name), $data->workflowUrl)'
        ), 
        array(
            'class' =>  'bootstrap.widgets.TbButtonColumn',
             'template'=>'{view} {delete}',           
             'buttons'=>array(
                 'view'  =>  array(
                     'label'    =>  '任务列表',
                     'url'      =>  'Yii::app()->controller->createUrl("task/index", array("job_id"=>$data->job_id))',
                     ),
                'delete'   =>  array(
                    'label'     =>  '删除查询',
                     'url'      =>  'Yii::app()->controller->createUrl("job/delete", array("job_id"=>$data->job_id))',
                    ),
                ),
        ),
    ),
));
?>

<?php $this->beginWidget('bootstrap.widgets.TbModal', array('id'=>'myModal')); ?>
 
<div class="modal-header">
    <a class="close" data-dismiss="modal">&times;</a>
    <h4>手动执行</h4>
</div>

<div class="modal-body">
<fieldset>
    <?php echo $form->errorSummary($model); ?>
    <?php echo $form->dateFieldRow($model, 'task_date', array('hint'=>'<strong>注意:</strong>请为任务填写一个基准时间')); ?>
</fieldset>
</div>

<div class="modal-footer">
<?php $this->widget('bootstrap.widgets.TbButton', array(
    'type'=>'primary',
    'buttonType'=>'ajaxSubmit',
    'label'=>'提交',
    'url'=>array('job/run'),
	'ajaxOptions'=>array(
        'beforeSend'=>  'checkSelect',
        'success'=>"js:function(data) {window.location.href=\"?r=task/index&type=$type\";}",
    ),
    'htmlOptions'=>array('data-dismiss'=>'modal'),
)); ?>
<?php $this->widget('bootstrap.widgets.TbButton', array(
    'label'=>'关闭',
    'url'=>'#',
    'htmlOptions'=>array('data-dismiss'=>'modal'),
)); ?>
</div>
<?php $this->endWidget(); ?>
<?php $this->endWidget(); ?>

